<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>0</h1>
<script>
    let count = 0;
  //开启定时器, 将方法作为参数进行传递时不加(),  调用方法时加()
  setInterval(f,10);
  function f() {
        count++;
        let h = document.querySelector("h1");
        h.innerText = count;
  }
  //匿名方法开启定时器
   let timer = setInterval(function () {
        console.log(count);
        if (count>=300){
            //停止定时器
            clearInterval(timer);
        }
    },1000);

  //开启只执行一次的定时器
    setTimeout(function () {
        console.log("时间到!");
    },2000);


</script>
</body>
</html>